<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=0, width=device-width"/>
        <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
        <title>密码修改</title>
        <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    </head>
    <style>
        body {
            background-color:#FFFFFF;
        }
        .headerCls{
        	width:100%;
        	/*height:50px;*/
        	padding:10px 20px 10px 20px;
        	/*position:absolute;top:10px;*/
			display: none;
        }
        .blankDivCls{
        	width:100%;
        	height:auto;
        	padding:10px 5px 10px 5px;
        	/*margin-top:60px;*/
        }
        .pwdDivCls{
        	width:100%;
        	height:40px;
        	margin-top:10px;
        	margin-bottom:10px;
        }
        .pwdLabelCls{
			width:25%;
			height:40px;
			line-height:40px;
			text-align:right;
			font-size:14px;
			float:left;
        }
        .pwdTextCls{
        	width:75%;
        	height:40px;
        	line-height:40px;
        	float:left;
        }
        .btnCls{
        	width:100%;
        	height:45px;
        	border-radius:10px;
        	background-color:#DB4537;
        	color:#FFFFFF;
        	font-size:20px;
        }
        .btnDivCls{
        	width:100%;
        	height:45px;
        	margin-top:50px;
        }
    </style>
    <body>
    	<header class="headerCls" id="force-update-tip">
    		<font style="color:#DB4537;font-size:16px;">提示：</font>
    		<span style="font-size:14px;">您当前密码过于简单，请修改后登录登陆！</span>
    	</header>
		 <div class="blankDivCls">
		 	<div class="pwdDivCls" style="margin-top:10px;">
		 		<div class="pwdLabelCls">旧密码：</div>
		 		<div class="pwdTextCls">
		 			<input type="password" id="oldPassword" value="" style="height:40px;line-height:40px;border-radius:10px;width:85%;"/>
		 			<i class="aui-input-addon aui-iconfont aui-icon-attention aui-text-default" tapmode onclick="showPassword(1);" id="showoldpass-btn"></i>
		 		</div>
		 	</div>
		 	<div class="pwdDivCls">
		 		<div class="pwdLabelCls">新密码：</div>
		 		<div class="pwdTextCls">
		 			<input type="password" id="newPassword" value="" style="height:40px;line-height:40px;border-radius:10px;width:85%;"/>
		 			<i class="aui-input-addon aui-iconfont aui-icon-attention aui-text-default" tapmode onclick="showPassword(2);" id="shownewpass-btn"></i>
		 		</div>
		 	</div>
		 	<div class="pwdDivCls">
		 		<div class="pwdLabelCls">确认密码：</div>
		 		<div class="pwdTextCls">
		 			<input type="password" id="okPassword" value="" style="height:40px;line-height:40px;border-radius:10px;width:85%;"/>
		 			<i class="aui-input-addon aui-iconfont aui-icon-attention aui-text-default" tapmode onclick="showPassword(3);" id="showokpass-btn"></i>
		 		</div>
		 	</div>
		 	<div class="btnDivCls">
		 		<button class="btnCls" onclick="modifyPwd()">修改</button>
<!--				<button class="btnCls" onclick="toggleTip()">切换</button>-->
		 	</div>
	    </div>
	    <footer style="width:100%;height:50px;padding:0px 20px 0px 20px;margin-top:40px;">
<!--	    	<font style="color:#DB4537;font-size:16px;">注：</font><span style="font-size:14px;">密码需要是字母、数字的组合，不能使用纯数字、纯字符串的密码。</span>-->
	    	<p style="color:#DB4537;font-size:14px;">密码需要同时满足以下规则</p>
	    	<p style="color:#DB4537;font-size:14px;">1、密码必须设置为8位以上（包含8位）</p>
	    	<p style="color:#DB4537;font-size:14px;">2、必须由大写字母+小写字母+符号+数字组成</p>
	    	<p style="color:#DB4537;font-size:14px;">3、数字不能出现3位以上的连续数字（包含3位）</p>
	    </footer>
    </body>
    <script src="../../script/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="../../script/client.api.js"></script>
    <script type="text/javascript" src="../../script/aui-alert.js"></script>
    <script type="text/javascript" src="../../script/api.js"></script>
    <script type="text/javascript" src="../../script/debug.js"></script>
    <script type="text/javascript" src="../../script/constant.js"></script>
    <script type="text/javascript" src="../../script/config.js"></script>
    <script type="text/javascript" src="../../script/common.js"></script>
    <script type="text/javascript" src="../../script/navigate.js"></script>
    <script type="text/javascript" src="../../script/doT.min.js"></script>
	<script type="text/javascript" src="../../script/jpush-api.js"></script>
	<script type="text/javascript" src="../../script/utils/aes.js"></script>
    <script>
		var topTipEl = document.getElementById("force-update-tip");
        apiready = function() {
        	api.parseTapmode();
			// console.log(JSON.stringify(api.pageParam));
			if(api.pageParam.forceUpdate){
				topTipEl.style.display = "block";
			}
        };

		function toggleTip(){
			topTipEl.style.display = topTipEl.style.display == "none" ? "block" : "none";
		}


        function showPassword(flag){
        	if(flag==1){
        		$api.attr($api.byId('oldPassword'),'type','text');
		        $api.removeCls($api.byId('showoldpass-btn'),'aui-icon-attention');
		        $api.addCls($api.byId('showoldpass-btn'),'aui-icon-attentionfill');
		        $api.attr($api.byId('showoldpass-btn'),'onclick','hidePassword(1);');
        	}else if(flag==2){
        		$api.attr($api.byId('newPassword'),'type','text');
		        $api.removeCls($api.byId('shownewpass-btn'),'aui-icon-attention');
		        $api.addCls($api.byId('shownewpass-btn'),'aui-icon-attentionfill');
		        $api.attr($api.byId('shownewpass-btn'),'onclick','hidePassword(2);');
        	}else{
        		$api.attr($api.byId('okPassword'),'type','text');
		        $api.removeCls($api.byId('showokpass-btn'),'aui-icon-attention');
		        $api.addCls($api.byId('showokpass-btn'),'aui-icon-attentionfill');
		        $api.attr($api.byId('showokpass-btn'),'onclick','hidePassword(3);');
        	}
	        api.parseTapmode();
	    }
	    function hidePassword(flag){
	    	if(flag==1){
        		$api.attr($api.byId('oldPassword'),'type','password');
	        	$api.removeCls($api.byId('showoldpass-btn'),'aui-icon-attentionfill');
	        	$api.addCls($api.byId('showoldpass-btn'),'aui-icon-attention');
	        	$api.attr($api.byId('showoldpass-btn'),'onclick','showPassword(1);');
        	}else if(flag==2){
        		$api.attr($api.byId('newPassword'),'type','password');
		        $api.removeCls($api.byId('shownewpass-btn'),'aui-icon-attentionfill');
	        	$api.addCls($api.byId('shownewpass-btn'),'aui-icon-attention');
	        	$api.attr($api.byId('shownewpass-btn'),'onclick','showPassword(2);');
        	}else{
        		$api.attr($api.byId('okPassword'),'type','password');
		        $api.removeCls($api.byId('showokpass-btn'),'aui-icon-attentionfill');
	        	$api.addCls($api.byId('showokpass-btn'),'aui-icon-attention');
	        	$api.attr($api.byId('showokpass-btn'),'onclick','showPassword(3);');
        	}
	        api.parseTapmode();
	    }

	    function modifyPwd(){
	    	var rightPwd = $api.getStorage(constant.LOGIN_PASSWORD);
	    	var oldPwd = $('#oldPassword').val();
	    	var newPwd = $('#newPassword').val();
	    	var okPwd = $('#okPassword').val();
	    	var opts = {};

	    	// if(oldPwd==null || oldPwd=="" || oldPwd=="undefined" || rightPwd!=oldPwd){
	    	// 	api.toast({msg: "旧密码不正确！", location: 'middle'});
	    	// 	return;
	    	// }

	    	if(newPwd == null || newPwd == '' || newPwd == 'undefined'){
	    		api.toast({msg: "新密码不能为空！", location: 'middle'});
	    		return;
	    	}

	    	if(newPwd == null || newPwd == '' || newPwd == 'undefined' || newPwd!=okPwd){
	    		api.toast({msg: "两次新密码输入不一致，请重新输入", location: 'middle'});
	    		return;
	    	}

	    	if(/^\d+$/.test(newPwd) || /^[a-zA-Z]+$/.test(newPwd)){
	    		api.toast({msg: "新密码过于简单，请重新输入，需要是字母与数字的组合!", location: 'middle'});
   				return;
			}

	    	if(newPwd.length<8){
	    		api.toast({msg: "新密码的位数不能小于8位!", location: 'middle'});
	    		return;
   			}

			var re = /^[0-9a-zA-Z!@#$%^&*()]*$/;
			if(!re.test(newPwd)){
				api.toast({msg: "密码只支持数字键上的特殊字符", location: 'middle'});
				return;
			}
			var mask = /^(?=.*?[a-zA-Z])(?=.*?\d)(?=.*?[A-Z])(?=.*?[!@#$%^&*()]).*$/;
			if(mask.test(newPwd) == false){
				//密码必须包含数字、字母以及数字键对应的特殊字符！
				api.toast({msg: "密码必须设置为8位以上（包含8位）、必须由大写字母+小写字母+符号+数字组成、数字不能出现3位以上的连续数字（包含3位）", location: 'middle'});
				return;
			}
			var mask2 = /^.*(0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){2}\d.*$/;
			if(mask2.test(newPwd) == true){
				api.toast({msg: "密码必须设置为8位以上（包含8位）、必须由大写字母+小写字母+符号+数字组成、数字不能出现3位以上的连续数字（包含3位）", location: 'middle'});
				return;
			}

	    	opts.oldPassword = AES.encryptPassword(oldPwd);
	    	opts.newPassword = AES.encryptPassword(newPwd);
	    	opts.loginVersion = "202109";

	    	showMask("处理中...");

	    	$client.modifyPassword(opts,function(ret, err) {
		        if (ret) {
		            if (ret.success) {
		            	//跳回至登录页
                		logout()
		               	hideMask();
		            } else if (ret.data_info) {
		                hideMask();
		                showToast(ret.data_info);
		            } else {
		                hideMask();
		                showToast("服务端错误，登录失败!");
		            }
		        } else {
		            hideMask();
		            showToast("服务异常，请重试");

		        }
		    });

	    }

	    /**
		 * 注销帐号
		 */
		function logout() {
			var user = $api.getStorage('user');
			var userId= user.userid;
			var fromPage = api.pageParam.fromPage;
		    //注销时设置islogin为false，表示未登录
		    $api.setStorage('AUTO_LOGIN', false);
		    //注销时提醒后台，改用户已注销
		    $client.userLoginOut( function(ret, err) {
		    });
		    openPage_login();

		    //如果是从设置中进入到修改密码页面，则修改成功后要跳转到登录页，并关闭原来的首页
		    if(fromPage=='setting'){
		    	closePage_home();
		    }

		    closePage_modifyPwd();
		}
    </script>
</html>
